package leetcode.easy.limit150;

public class No111 {
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    // 记录最小深度（根节点到最近的叶子节点的距离）
    private static int minDepth = Integer.MAX_VALUE;
    // 记录当前遍历到的节点深度
    private static int currentDepth = 0;

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        find(root);
        return 0;
    }

    public static void find(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        currentDepth++;
        if (treeNode.left == null && treeNode.right == null) {
            minDepth = Math.min(minDepth, currentDepth);
        }
        find(treeNode.left);
        find(treeNode.right);
        currentDepth--;
    }

    public static void main(String[] args) {

    }


}
